import libs.common_func as c

def get_say(s):
    l = len(s)
    res = ''
    count = 1
    for (i, c) in enumerate(s):
        if (i + 1 > l - 1) or (c != s[i + 1]):
            res += str(count) + c
            count = 1
        else:
            count += 1

    return res

cachedSay = c.cached(get_say)


class Solution:
    def countAndSay(self, n):
        """
        :type n: int
        :rtype: str
        """
        curr = '1'
        for i in range(n):
            if i == n - 1:
                return curr
            else:
                curr = cachedSay(curr)


s = Solution()
print('ss', s.countAndSay(1))
print('ss', s.countAndSay(2))
print('ss', s.countAndSay(4))
print('ss', s.countAndSay(5))
# print(cachedSay('1'))
